	layui.use(['table', 'form', 'jquery', 'common', 'laydate'], function() {
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;
			let common = layui.common;
			let laydate = layui.laydate;
			let cols = [
				[{
					field: "pid",
					title: "pid",
					unresize: "true",
					align: "center"
				}, {
					field: "key",
					title: "KEY",
					unresize: "true",
					align: "center"
				}, {
					field: 'user',
					title: '自定义登陆账号/密码',
					width: 200,
					align: 'center',
					templet:function(d){
					    return d.user + ' / ' + d.pass 
					}
				}, {
					field: "qq",
					title: "QQ",
					unresize: "true",
					align: "center"
				},{
					field: "money",
					title: "额度",
					unresize: "true",
					align: "center"
				},{
					field: "qxqr",
					title: "旗下二维码数量",
					unresize: "true",
					align: "center",
					width:200,
					templet:function(d){
					    return d.qxqr
					}
				},{
					field: "mghy",
					title: "免挂会员",
					unresize: "true",
					align: "center",
					templet:function(d){
					    return d.mghy
					}
				},{
					field: "sktj",
					title: "收款统计",
					unresize: "true",
					align: "center",
					templet:function(d){
					    return d.sktj
					}
				}, {
					field: "zt",
					unresize: "true",
					title: "状态",
					align: "center",
					templet: "#status"
				}, 
				{
					title: '操作',
					toolbar: '#options',
					unresize: true,
					align: 'center',
					width: 180,
				}]
			]

			table.render({
				elem: '#news',
				id: 'news',
				url: '/h/ajax/usergetDataList',
				page: true,
				cols: cols,
				cellMinWidth: 100,
				skin: 'line',
				toolbar: '#toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports']
			});

			table.on('tool(news)', function(obj) {
				if (obj.event === 'remove') {
					window.remove(obj);
				} else if (obj.event === 'edit') {
					window.edit(obj);
				} else if (obj.event === 'password') {
					window.password(obj);
				}
			});

			form.on('submit(user-query)', function(data) {
				// console.log(data.field)
				table.reload('news', {
					where: data.field,
					page:{curr:1}
				})
				return false;
			});

			table.on('toolbar(news)', function(obj) {
				if (obj.event === 'add') {
					window.add();
				} else if (obj.event === 'refresh') {
					window.refresh();
				}
			});


			// 修改状态
			form.on("switch(status)", function(data) {
			       
    				var pid = this.value;
    				var load = layer.load();
    				$.ajax({
                        url: "/h/ajax/userstatus",
                        type: "POST",
                        dataType: 'json',
                        data:{
                            pid:pid
                        },
                        success: function(result) {
                            layer.close(load);
                            if (result.code == 200) {
                                layer.msg(result.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function() {
                                    table.reload('news');
                                });
                                
                            } else {
                                layer.msg(result.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        },
                        error:function(){
                            layer.close(load);
                            layer.msg("服务器错误！", {
                                icon: 2,
                                time: 1000
                            });
                        }
                    })
    		});
			//弹出窗设置 自己设置弹出百分比
			function screen() {
				if (typeof width !== 'number' || width === 0) {
					width = $(window).width() * 0.8;
				}
				if (typeof height !== 'number' || height === 0) {
					height = $(window).height() * 0.5;
				}
				return [width + 'px', height + 'px'];
			}

			// 添加数据
			window.add = function() {
				layer.open({
					type: 2,
					maxmin: true,
					title: '新增管理',
					shade: 0.1,
					area: screen(),
					content: "User/add"
				});
			}

			// 发送添加数据内容
			form.on('submit(addSave)', function(data) {
				$.ajax({
					data: JSON.stringify(data.field),
					url: "/h/ajax/Add_user",
					contentType: 'application/json',
					dataType: 'json',
					type: 'post',
					success: function(res) {
						if (res.code == 200) {
							layer.msg(res.msg, {
								icon: 1,
								time: 1000
							}, function() {
								parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
								parent.layui.table.reload("news");
							});
						} else {
							layer.msg(res.msg, {
								icon: 2,
								time: 1000
							});
						}
					},
					error:function(){
					    layer.msg("服务器错误！", {
                            icon: 2,
                            time: 1000
                        });
					}
				})
				return false;
			});

			// 修改数据
			window.password = function(obj) {
				layer.open({
					type: 2,
					maxmin: true,
					title: '修改用户密码管理',
					shade: 0.1,
					area: screen(),
					content: 'User/editPwd?id=' + obj.data['pid']
				});
			}
			// 发送修改数据内容
			form.on('submit(editPwdSave)', function(data) {
				$.ajax({
					data: JSON.stringify(data.field),
					url: "/h/ajax/Edit_gaimi",
					contentType: 'application/json',
					dataType: 'json',
					type: 'post',
					success: function(res) {
						if (res.code == 200) {
							layer.msg(res.msg, {
								icon: 1,
								time: 1000
							}, function() {
								parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
								parent.layui.table.reload("news");
							});
						} else {
							layer.msg(res.msg, {
								icon: 2,
								time: 1000
							});
						}
					},
					error:function(){
					    layer.msg("服务器错误！", {
                            icon: 2,
                            time: 1000
                        });
					}
				})
				return false;
			});

			// 修改数据
			window.edit = function(obj) {
				layer.open({
					type: 2,
					maxmin: true,
					title: '修改用户管理',
					shade: 0.1,
					area: screen(),
					content: 'User/edit?id=' + obj.data['pid']
				});
			}

			// 发送修改数据内容
			form.on('submit(editSave)', function(data) {
				$.ajax({
					data: JSON.stringify(data.field),
					url: "/h/ajax/Edit_user",
					contentType: 'application/json',
					dataType: 'json',
					type: 'post',
					success: function(res) {
						if (res.code == 200) {
							layer.msg(res.msg, {
								icon: 1,
								time: 1000
							}, function() {
								parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
								parent.layui.table.reload("news");
							});
						} else {
							layer.msg(res.msg, {
								icon: 2,
								time: 1000
							});
						}
					},
					error:function(){
					    layer.msg("服务器错误！", {
                            icon: 2,
                            time: 1000
                        });
					}
				})
				return false;
			});

			// 数据删除
			window.remove = function(obj) {
				layer.confirm('确定要删除该用户吗？', {
					icon: 3,
					title: '提示'
				}, function(index) {
					layer.close(index);
					let loading = layer.load();
					$.ajax({
						url: '/h/ajax/userremove',
						data: {
							id: obj.data['pid']
						},
						dataType: 'json',
						type: 'POST',
						success: function(res) {
							layer.close(loading);
							//判断有没有权限
							 if (res.code == 200) {
								layer.msg(res.msg, {
									icon: 1,
									time: 1000
								}, function() {
									obj.del();
								});
							} else {
								layer.msg(res.msg, {
									icon: 2,
									time: 1000
								});
							}
						},
    					error:function(){
    					    layer.close(loading);
    					    layer.msg("服务器错误！", {
                                icon: 2,
                                time: 1000
                            });
    					}
					})
				});
			}

			window.refresh = function(param) {
				table.reload('news');
			}
		})